home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / TransSkel / Demos / C Demos / HierMenu / HierMenu.c next >
Encoding:
C/C++ Source or Header  |  1994-02-21  |  3.5 KB  |  145 lines  |  [TEXT/KAHL]

  1. /*
  2.  * Simple application showing how to create hierarchical menus with TransSkel.
  3.  *
  4.  * Nothing is actually done with any of the menu selections except Quit from
  5.  * the File menu.
  6.  *
  7.  * 16 Feb 94 Version 1.00, Paul DuBois
  8.  * 21 Feb 94
  9.  * - Updated for TransSkel 3.11.
  10.  */
  11.  
  12. # include    "TransSkel.h"
  13.  
  14.  
  15. # define    aboutAlrtRes    1000        /* About box resource number*/
  16.  
  17.  
  18. # define    fileMenuNum        1000        /* File menu */
  19. # define    demoMenuNum        1001        /* Demo menu */
  20. # define    sub1MenuNum        231            /* Demo menu submenus */
  21. # define    sub2MenuNum        232
  22. # define    sub3MenuNum        233
  23. # define    demo2MenuNum    1005        /* Demo2 menu resource number */
  24. # define    sub21MenuNum    241            /* Demo2 menu submenus */
  25. # define    sub22MenuNum    242
  26. # define    sub23MenuNum    243
  27.  
  28.  
  29. /* file menu item numbers */
  30.  
  31. typedef enum
  32. {
  33.     quit = 1
  34. };
  35.  
  36.  
  37.  
  38. /* -------------------------------------------------------------------- */
  39. /*                        Menu handling procedures                        */
  40. /* -------------------------------------------------------------------- */
  41.  
  42.  
  43. /*
  44.  * Handle selection of "About Hello..." item from Apple menu
  45.  */
  46.  
  47. static pascal void
  48. DoAppleMenu (short item)
  49. {
  50.     (void) SkelAlert (aboutAlrtRes, SkelDlogFilter (nil, true),
  51.                                         skelPositionOnParentDevice);
  52.     SkelRmveDlogFilter ();
  53. }
  54.  
  55.  
  56. /*
  57.  * Process selection from File menu.
  58.  */
  59.  
  60. static pascal void
  61. DoFileMenu (short item)
  62. {
  63.     switch (item)
  64.     {
  65.     case quit:
  66.         SkelStopEventLoop ();
  67.         break;
  68.     }
  69. }
  70.  
  71.  
  72. /*
  73.  * Initialize menus.  Tell TransSkel to process the Apple menu
  74.  * automatically, and associate the proper procedure with the
  75.  * File menu.
  76.  *
  77.  * \311 is the ellipsis character.
  78.  */
  79.  
  80. static void
  81. SetupMenus (void)
  82. {
  83. MenuHandle    m;
  84.  
  85.     SkelApple ("\pAbout HierMenu\311", DoAppleMenu);
  86.     m = NewMenu (fileMenuNum, "\pFile");
  87.     AppendMenu (m, "\pQuit/Q");
  88.     (void) SkelMenu (m, DoFileMenu, nil, false, false);
  89.  
  90.     /*
  91.      * Create hierarchical menu using NewMenu().  The parent menu
  92.      * items are specified as having submenus by indicating 033 (0x1b)
  93.      * as the command-key equivalent.  The submenus are attached by
  94.      * specifying the submenu numbers as the item mark numbers for
  95.      * items in the parent menu.
  96.      */
  97.  
  98.     m = NewMenu (demoMenuNum, "\pDemo");
  99.     AppendMenu (m, "\pItem 1/\033;Item 2/\033;Item 3/\033");
  100.     SetItemMark (m, 1, sub1MenuNum);
  101.     SetItemMark (m, 2, sub2MenuNum);
  102.     SetItemMark (m, 3, sub3MenuNum);
  103.     (void) SkelMenu (m, nil, nil, false, false);
  104.     m = NewMenu (sub1MenuNum, "\p");
  105.     AppendMenu (m, "\pSubitem 1.1;Subitem 1.2;Subitem 1.3");
  106.     (void) SkelMenu (m, nil, nil, true, false);
  107.     m = NewMenu (sub2MenuNum, "\p");
  108.     AppendMenu (m, "\pSubitem 2.1;Subitem 2.2;Subitem 2.3");
  109.     (void) SkelMenu (m, nil, nil, true, false);
  110.     m = NewMenu (sub3MenuNum, "\p");
  111.     AppendMenu (m, "\pSubitem 3.1;Subitem 3.2;Subitem 3.3");
  112.     (void) SkelMenu (m, nil, nil, true, false);
  113.  
  114.     /*
  115.      * Create hierarchical menu from resources using GetMenu().
  116.      * All the submenu information is specified in the resources.
  117.      */
  118.  
  119.     m = GetMenu (demo2MenuNum);
  120.     (void) SkelMenu (m, nil, nil, false, false);
  121.     m = GetMenu (sub21MenuNum);
  122.     (void) SkelMenu (m, nil, nil, true, false);
  123.     m = GetMenu (sub22MenuNum);
  124.     (void) SkelMenu (m, nil, nil, true, false);
  125.     m = GetMenu (sub23MenuNum);
  126.     (void) SkelMenu (m, nil, nil, true, false);
  127.  
  128.     DrawMenuBar ();
  129. }
  130.  
  131.  
  132. /* -------------------------------------------------------------------- */
  133. /*                                    Main                                */
  134. /* -------------------------------------------------------------------- */
  135.  
  136.  
  137. int
  138. main (void)
  139. {
  140.     SkelInit ((SkelInitParamsPtr) nil);    /* initialize */
  141.     SetupMenus ();                        /* install menu handlers */
  142.     SkelEventLoop ();                    /* loop 'til Quit selected */
  143.     SkelCleanup ();                        /* clean up */
  144. }
  145.